package com.lambda.lambda.lambda;

import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * lambda表达式练习
 */
public class TestLambda {

    List<Student> students= Arrays.asList(
            new Student("张三",20,100),
            new Student("李四",10,88),
            new Student("王五",30,78)
    );

    @Test
    public void test(){
      Collections.sort(students,(s1,s2)->{
          if(s1.getAge().equals(s2.getAge())){
              return s1.getName().compareTo(s2.getName());
          }else{
              return Integer.compare(s1.getAge(),s2.getAge());
          }
      });
        for (Student student : students) {
            System.out.println(student);
        }
    }
    @Test
     public void test2(){
        System.out.println(change("  hello  ", c -> c.trim()));
        System.out.println(change("hello", c -> c.toUpperCase()));
    }


    public String change(String str,Change c){
       return c.getValue(str);
    }

    @Test
    public void test3(){
        op(1L,2L, (x,y)->x+y);
        op(1L,2L, (x,y)->x*y);
    }

    public void op(Long l1,Long l2,MyFunction<Long,Long> mf){
        System.out.println(mf.getValue(l1,l2));
    }

}
